package EWCore.Items.Attributes
{
	import EWCore.Utilities.Useful;
	
	/**
	 * 属性类型
	 * */
	public class AttributeType
	{
		public var auto_id:int;
		public var shortname:String;
		public var fullname:String;
		public var quality:int;
		public var expression:String;
		public var restricttype:String;
		public static var ITEMTYPES:Object;
		public static var ATTRIBUTETYPES:Object;
		
		/**
		 * 是否相等
		 * @param i_AttributeType 属性类型（可以为AttributeType实例或简称字符串）
		 * 
		 * */
		public function IsEqualTo(i_AttributeType:*):Boolean
		{
			if(i_AttributeType is AttributeType)
				return (i_AttributeType.shortname==this.shortname);
			else
				return i_AttributeType==this.shortname;
		}
		
		/**
		 * 从Object加载AttributeType
		 * @param data 数据
		 * 
		 * */
		public function LoadFromObject(data:Object):void
		{
			this.auto_id = data.auto_id;
			this.shortname = data.shortname;
			this.fullname = data.fullname;
			this.quality = data.quality;
			this.expression = data.expression;
			this.restricttype = data.restricttype;	
		}
		
		/**
		 * 按简称获取属性
		 * @param i_ShortName 简称
		 * 
		 * */
		public static function GetTypeByName(i_ShortName:String):AttributeType
		{
			var t_AttributeType:AttributeType = new AttributeType();
			t_AttributeType.LoadFromObject(AttributeType.ATTRIBUTETYPES[i_ShortName]);
			return t_AttributeType;
		}
		/**
		 * 按品质和物品类型随机获取属性
		 * @param i_Quality 品质
		 * @param i_Type 物品类型
		 * */
		public static function GetTypeRand(i_Quality:int, i_Type:String):AttributeType
		{
			var subarr:Array = AttributeType.ATTRIBUTETYPES._BYTYPE_[i_Type][i_Quality];
			if(subarr==null)
				return null;
			return GetTypeByName(subarr[Useful.Random(0,subarr.length-1)])
			
		}
		
		/**
		 * 属性是否为某类型物品拥有
		 * @param i_Type 类型
		 * 
		 * */
		public function IsInType(i_Type:String):Boolean
		{
			if(i_Type!="*" && AttributeType.ITEMTYPES[i_Type]==undefined)
				return false;
			return true;
		}
	}
}